<?php
declare (strict_types = 1);

namespace app\adminapi\controller\system\organize;

use adminmatrix\annotation\auth\IsPermission;
use adminmatrix\server\app\server\JsonService;
use app\adminapi\logic\system\organize\DepartmentLogic;
use app\adminapi\logic\system\organize\PositionLogic;
use think\exception\HttpException;
use think\Request;
use adminmatrix\server\app\adminMatrix;
use think\response\Json;

class PositionController extends AdminMatrix
{
    public function lists(){
        return $this->dataLists();
    }

    public function save( Request $request , PositionLogic $positionLogic) : Json
    {
        try {
            $positionLogic->save($request);
            return JsonService::success('新增职务成功');
        } catch (HttpException $e)
        {
            return  JsonService::fail($e->getMessage());
        }
    }

    public function update( Request $request , PositionLogic $positionLogic) : Json
    {
        try {
            $positionLogic->update($request);
            return JsonService::success('编辑职务成功');
        } catch (HttpException $e)
        {
            return  JsonService::fail($e->getMessage());
        }
    }

    public function delete(int $id ,  Request $request , PositionLogic $positionLogic) : Json
    {
        try {
            $positionLogic->delete($id);
            return JsonService::success('删除职务成功');
        } catch (HttpException $e)
        {
            return  JsonService::fail($e->getMessage());
        }
    }

    #[IsPermission]
    public function getPositionList(Request $request , PositionLogic $positionLogic) : Json
    {
        try {
            $lists = $positionLogic -> get($request);
            return  JsonService::success('' , $lists);
        } catch (HttpException $e)
        {
            return JsonService::fail($e->getMessage());
        }
    }
}
